﻿@model StoreModel

@using Telerik.Web.Mvc.UI;

@Html.ValidationSummary(false)
@Html.HiddenFor(model => model.Id)
@Html.Telerik().TabStrip().Name("store-edit").Items(x =>
{
    var tabInfo = x.Add().Text(T("Admin.Catalog.Stores.Info").Text).Content(TabInfo().ToHtmlString());
    TabStripItemBuilder tabSeo = null;
    if (Model.IsStoreAdmin)
    {
        tabSeo = x.Add().Text(T("Admin.Common.SEO").Text).Content(TabSeo().ToHtmlString());
    }

    TabStripItemBuilder tabBranches = null;
    if (Model.Id > 0 && Model.IsStoreAdmin)
        tabBranches = x.Add().Text(T("Admin.Catalog.Stores.Branches").Text).Content(TabBranches().ToHtmlString());

    var selectedTab = (string)ViewData["selectedTab"];
    switch (selectedTab)
    {
        case "info":
            tabInfo.Selected(true);
            break;
        case "tabSeo":
            tabSeo.Selected(true);
            break;
        case "tabBranches":
            tabBranches.Selected(true);
            break;
        default:
            tabInfo.Selected(true);
            break;
    }

    //generate an event
    EngineContext.Current.Resolve<IEventPublisher>().Publish(new AdminTabStripCreated(x, "store-edit"));
})

@helper TabInfo()
{
    @(Html.LocalizedEditor<StoreModel, StoreLocalizedModel>("store-info-localized",
    @<table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Locales[item].Name):
            </td>
            <td class="adminData">
                @if (Model.IsStoreAdmin)
                {
                    @Html.EditorFor(model => Model.Locales[item].Name)
                    @Html.ValidationMessageFor(model => model.Locales[item].Name)
                }
                else
                {
                    @Html.DisplayFor(model => Model.Locales[item].Name)
                    @Html.HiddenFor(model => model.Locales[item].Name)
                }
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Locales[item].Description):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Locales[item].Description, "RichEditor")
                @Html.ValidationMessageFor(model => model.Locales[item].Description)
            </td>
        </tr>
        <tr>
            <td colspan="2">
                @Html.HiddenFor(model => model.Locales[item].LanguageId)
            </td>
        </tr>
    </table>
                ,
                @<table class="adminContent">
                    <tr>
                        <td class="adminTitle">
                            @Html.NopLabelFor(model => model.Name):
                        </td>
                        <td class="adminData">
                            @if (Model.IsStoreAdmin)
                            {
                                @Html.EditorFor(model => model.Name)
                                @Html.ValidationMessageFor(model => model.Name)
                            }
                            else
                            {
                                @Html.DisplayFor(model => model.Name)
                                @Html.HiddenFor(model => model.Name)
                            }
                        </td>
                    </tr>
                    <tr>
                        <td class="adminTitle">
                            @Html.NopLabelFor(model => model.Description):
                        </td>
                        <td class="adminData">
                            @Html.EditorFor(x => x.Description, "RichEditor.Telerik")
                            @Html.ValidationMessageFor(model => model.Description)
                        </td>
                    </tr>
                </table>))

    if (Model.IsStoreAdmin)
    {
        <table class="adminContent">
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.PictureId)
                </td>
                <td class="adminData">
                    @Html.EditorFor(model => model.PictureId)
                    @Html.ValidationMessageFor(model => model.PictureId)
                </td>
            </tr>
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.PriceRanges):
                </td>
                <td class="adminData">
                    @Html.EditorFor(model => model.PriceRanges)
                    @Html.ValidationMessageFor(model => model.PriceRanges)
                </td>
            </tr>
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.Published):
                </td>
                <td class="adminData">
                    @if (Model.IsAdmin)
                    {
                        @Html.EditorFor(model => model.Published)
                        @Html.ValidationMessageFor(model => model.Published)
                    }
                    else
                    {
                        @Html.DisplayFor(model => model.Published)
                    }
                </td>
            </tr>
            @*
                TODO: Need to restrict the "Featured" element to Admin only?
                        OR, is the Create / Update ability already Admin only?
            *@
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.Featured):
                </td>
                <td class="adminData">
                    @if (Model.IsAdmin)
                    {
                        @Html.EditorFor(model => model.Featured)
                        @Html.ValidationMessageFor(model => model.Featured)
                    }
                    else
                    {
                        @Html.DisplayFor(model => model.Featured)
                    }
                </td>
            </tr>
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.DisplayOrder):
                </td>
                <td class="adminData">
                    @Html.EditorFor(model => model.DisplayOrder)
                    @Html.ValidationMessageFor(model => model.DisplayOrder)
                </td>
            </tr>
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.MinOrderSubtotalAmount):
                </td>
                <td class="adminData">
                    @Html.EditorFor(model => model.MinOrderSubtotalAmount)
                    @Html.ValidationMessageFor(model => model.MinOrderSubtotalAmount)
                </td>
            </tr>
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.MinOrderTotalAmount):
                </td>
                <td class="adminData">
                    @Html.EditorFor(model => model.MinOrderTotalAmount)
                    @Html.ValidationMessageFor(model => model.MinOrderTotalAmount)
                </td>
            </tr>
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.CustomerEmail):
                </td>
                <td class="adminData">
                    @Html.EditorFor(model => model.CustomerEmail)
                    @Html.ValidationMessageFor(model => model.CustomerEmail)
                </td>
            </tr>
            @if (Model.IsAdmin)
            {
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.AdminCustomerId):
                    </td>
                    <td class="adminData">
                        @Html.EditorFor(x => x.AdminCustomerId)
                        @Html.ValidationMessageFor(model => model.AdminCustomerId)
                    </td>
                </tr>
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.MonthlyCharge):
                    </td>
                    <td class="adminData">
                        @Html.EditorFor(x => x.MonthlyCharge)
                        @Html.ValidationMessageFor(model => model.MonthlyCharge)
                    </td>
                </tr>
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.ServiceChargeRate):
                    </td>
                    <td class="adminData">
                        @Html.EditorFor(x => x.ServiceChargeRate)
                        @Html.ValidationMessageFor(model => model.ServiceChargeRate)
                    </td>
                </tr>
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.StorageAmount):
                    </td>
                    <td class="adminData">
                        @Html.EditorFor(x => x.StorageAmount)
                        @Html.ValidationMessageFor(model => model.StorageAmount)
                    </td>
                </tr>
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.StorageChargeRate):
                    </td>
                    <td class="adminData">
                        @Html.EditorFor(x => x.StorageChargeRate)
                        @Html.ValidationMessageFor(model => model.StorageAmount)
                    </td>
                </tr>
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.TransactionProcessingChargeRate):
                    </td>
                    <td class="adminData">
                        @Html.EditorFor(x => x.TransactionProcessingChargeRate)
                        @Html.ValidationMessageFor(model => model.StorageAmount)
                    </td>
                </tr>
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.RegionId):
                    </td>
                    <td class="adminData">
                        <select class="form-control" name="RegionId">
                            @foreach (var region in Model.RegionCollection)
                            {
                                if (Model.RegionId == region.Id)
                                {
                                    <option value="@region.Id" selected>@region.Name</option>
                                }
                                else
                                {
                                    <option value="@region.Id">@region.Name</option>
                                }
                            }
                        </select>
                    </td>
                </tr>
            }
            else
            {
                @Html.HiddenFor(x => x.AdminCustomerId)
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.MonthlyCharge):
                    </td>
                    <td class="adminData">
                        @Html.DisplayFor(x => x.MonthlyCharge)
                    </td>
                </tr>
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.ServiceChargeRate):
                    </td>
                    <td class="adminData">
                        @Html.DisplayFor(x => x.ServiceChargeRate)
                    </td>
                </tr>
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.StorageAmount):
                    </td>
                    <td class="adminData">
                        @Html.DisplayFor(x => x.StorageAmount)
                    </td>
                </tr>
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.StorageChargeRate):
                    </td>
                    <td class="adminData">
                        @Html.DisplayFor(x => x.StorageChargeRate)
                    </td>
                </tr>
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.TransactionProcessingChargeRate):
                    </td>
                    <td class="adminData">
                        @Html.DisplayFor(x => x.TransactionProcessingChargeRate)
                    </td>
                </tr>
            }
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.BannerId)
                </td>
                <td class="adminData">
                    @Html.EditorFor(model => model.BannerId)
                    @Html.ValidationMessageFor(model => model.BannerId)
                </td>
            </tr>
        </table>
    }
    else
    {
        @Html.HiddenFor(model => model.CustomerEmail)
    }

}
@helper TabSeo()
{
    if (Model.IsStoreAdmin)
    {
        @(Html.LocalizedEditor<StoreModel, StoreLocalizedModel>("store-seo-localized",
        @<table class="adminContent">
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.Locales[item].MetaKeywords):
                </td>
                <td class="adminData">
                    @Html.EditorFor(model => model.Locales[item].MetaKeywords)
                    @Html.ValidationMessageFor(model => model.Locales[item].MetaKeywords)
                </td>
            </tr>
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.Locales[item].MetaDescription):
                </td>
                <td class="adminData">
                    @Html.TextAreaFor(model => model.Locales[item].MetaDescription)
                    @Html.ValidationMessageFor(model => model.Locales[item].MetaDescription)
                </td>
            </tr>
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.Locales[item].MetaTitle):
                </td>
                <td class="adminData">
                    @Html.TextAreaFor(model => model.Locales[item].MetaTitle)
                    @Html.ValidationMessageFor(model => model.Locales[item].MetaTitle)
                </td>
            </tr>
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.Locales[item].SeName):
                </td>
                <td class="adminData">
                    @Html.TextAreaFor(model => model.Locales[item].SeName)
                    @Html.ValidationMessageFor(model => model.Locales[item].SeName)
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    @Html.HiddenFor(model => model.Locales[item].LanguageId)
                </td>
            </tr>
        </table>
               ,
            @<table class="adminContent">
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.MetaKeywords):
                    </td>
                    <td class="adminData">
                        @Html.EditorFor(x => x.MetaKeywords)
                        @Html.ValidationMessageFor(model => model.MetaKeywords)
                    </td>
                </tr>
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.MetaDescription):
                    </td>
                    <td class="adminData">
                        @Html.TextAreaFor(x => x.MetaDescription)
                        @Html.ValidationMessageFor(model => model.MetaDescription)
                    </td>
                </tr>
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.MetaTitle):
                    </td>
                    <td class="adminData">
                        @Html.TextAreaFor(x => x.MetaTitle)
                        @Html.ValidationMessageFor(model => model.MetaTitle)
                    </td>
                </tr>
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.SeName):
                    </td>
                    <td class="adminData">
                        @Html.TextAreaFor(x => x.SeName)
                        @Html.ValidationMessageFor(model => model.SeName)
                    </td>
                </tr>
            </table>))
        <table class="adminContent">
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.PageSize):
                </td>
                <td class="adminData">
                    @Html.EditorFor(x => x.PageSize)
                    @Html.ValidationMessageFor(model => model.PageSize)
                </td>
            </tr>
        </table>
    }
}
@helper TabBranches()
{
    if (Model.IsStoreAdmin)
    {
        @(Html.Telerik().Grid<BranchModel>().Name("store-branches-grid")
            .DataKeys(keys =>
            {
                keys.Add(x => x.Id).RouteKey("branchId");
            })
            .DataBinding(binding =>
            {
                binding.Ajax()
                    .Select("BranchesSelect", "Store", new { storeId = Model.Id })
                    .Delete("BranchDelete", "Store", new { storeId = Model.Id });
            })
            .Columns(columns =>
            {
                columns.Bound(x => x.Name);
                columns.Bound(x => x.DisplayOrder);
                columns.Bound(x => x.Website);
                columns.Bound(x => x.Email);
                columns.Bound(x => x.PhoneNumber);
                columns.Bound(x => x.FaxNumber);
                columns.Bound(x => x.Id)
                    .ClientTemplate("<div>"
                            + "<#= Address1 #><br />"
                            + "<#= Address2 #><br />"
                            + "<#= City #>, <#= StateProvinceName #>, <#= ZipPostalCode #><br />"
                            + "<#= CountryName #><br />"
                            + "</div>")
                    .Title("Branch");
                columns.Bound(x => x.IsMainBranch)
                    .ClientTemplate("<img alt='' src='" + Url.Content("~/subsites/Administration/Content/images/") + "active-<#= IsMainBranch #>.gif' />")
                    .Centered()
                    .Width(100);
                columns.Bound(x => x.Id)
                    .Template(x => Html.ActionLink(T("Admin.Catalog.Stores.Branches.Fields.MarkAsMainBranch").Text, "MarkAsMainBranch", new { branchid = x.Id, storeId = @Model.Id }, new { @class = "t-button" }))
                    .ClientTemplate("<a class='t-button' href=\"" + @Url.Content("~/Admin/Store/MarkAsMainBranch?storeId=") + @Model.Id + "&branchid=<#= Id #>\">" + T("Admin.Catalog.Stores.Branches.Fields.MarkAsMainBranch").Text + "</a>")
                    .Centered()
                    .HeaderTemplate(T("Admin.Catalog.Stores.Branches.Fields.MarkAsMainBranch").Text);
                columns.Bound(x => x.Id)
                    .ClientTemplate("<a href=\"" + @Url.Content("~/Admin/Store/BranchEdit?storeId=") + @Model.Id + "&branchid=<#= Id #>\">" + T("Admin.Common.Edit").Text + "</a>")
                    .Title("Edit");
                columns.Command(commands =>
                {
                    commands.Delete().Text(T("Admin.Common.Delete").Text);
                })
                .Title("Delete");
            })
        )
        <div class="clear">
        </div>
        @Html.HiddenFor(model => model.MainBranchId)
        <p>
            <strong>
                <input type="button" class="t-button" onclick="location.href='@Url.Action("BranchCreate", new { storeId = Model.Id })'" value='@T("Admin.Catalog.Stores.Branches.Fields.AddNew")' />
            </strong>
        </p>
    }
}


